/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.fzhucc.modules.sciTechnologyDemand.repository;

import com.fzhucc.modules.sciPersonnelInfo.domain.SciPersonnelInfoMate;
import com.fzhucc.modules.sciTechnologyDemand.domain.SciTechnologyDemand;
import com.fzhucc.modules.sciTechnologyDemand.domain.SciTechnologyDemandMate;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author yyg
 * @website https://eladmin.vip
 * @date 2023-12-15
 **/
public interface SciTechnologyDemandMateRepository extends JpaRepository<SciTechnologyDemandMate, Integer>, JpaSpecificationExecutor<SciTechnologyDemandMate> {

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand_mate where sp_id=:spId and td_id=:tdId order by matesort")
    List<SciTechnologyDemandMate> findBySpIdTdId(int spId, int tdId);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand_mate where td_id=:tdId order by matesort")
    List<SciTechnologyDemandMate> findByTdId(int tdId);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand_mate where td_id=:tdId and matesort = 2")
    List<SciTechnologyDemandMate> findByTdIdWithMateSortSecond(int tdId);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand_mate where td_id=:tdId order by matesort")
    Page<SciTechnologyDemandMate> findByTdIdPage(int tdId, Pageable pageable);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand_mate where td_id=:tdId and is_select =1 order by matesort")
    List<SciTechnologyDemandMate> findIsSelect(int tdId);

    @Query(nativeQuery = true, value = "SELECT m.* FROM tb_sci_technology_demand_mate as m,tb_sci_personnel_info as d WHERE 1=1 and m.td_id=:tdId and m.sp_id=d.id and d.zqxname like :name")
    Page<SciTechnologyDemandMate> findAllWithOutParmByLikeMName(int tdId, String name, Pageable pageable);
}